home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / windc.exe / SAMPLE2.C < prev    next >
C/C++ Source or Header  |  1991-07-07  |  11KB  |  290 lines

  1.     /* sample of menu functions */
  2. #include <stdio.h>
  3. #include "wwindefs.h"                /* window headers */
  4. #include "wwinstpr.h"
  5.  
  6. /* subroutine prototypes */
  7. void LoadUpMenus();
  8. int DoMenus();
  9. void DialHandler(struct WWinRC ret);
  10.  
  11. extern WWVIDMEM WWscreenp;             /* pointer to screen memory */
  12. extern unsigned int WWScreenLength;    /* access to WW default */
  13.  
  14.  
  15. /* define caption window - globally */
  16. struct WWinstruc Caption =
  17.   {"Caption",20,5,10,60, WHITE,BLACK,SLN_BDR,WHITE,BLACK,INV_CSR};
  18.  
  19. /* define the menu windows */
  20. struct WWinstruc TopLine =
  21.   {"TopLine",1,1,2,70, RED,WHITE,NO_BDR,0,0,INV_CSR};
  22. struct WWinstruc DropWin[6] = {
  23.   {"File",3,9,4,15,BLUE,WHITE,SLN_BDR,WHITE,BLUE,INV_CSR},
  24.   {"Baud",3,6,11,5,BLUE,WHITE,SLN_BDR,WHITE,BLUE,INV_CSR},
  25.   {"Parity",3,3,22,5,BLUE,WHITE,SLN_BDR,WHITE,BLUE,INV_CSR},
  26.   {"Transfer",3,5,31,11,BLUE,WHITE,SLN_BDR,WHITE,BLUE,INV_CSR},
  27.   {"Error",3,2,42,6,BLUE,WHITE,SLN_BDR,WHITE,BLUE,INV_CSR},
  28.   {"Dial",3,4,49,30,BLUE,WHITE,SLN_BDR,WHITE,BLUE,INV_CSR} };
  29.  
  30. unsigned int *hold_Dial_mem_ptr; /* hold for Dial Memorypointer      */
  31.                  /* Dial window is mapped on dial #s */
  32. main()
  33.   {
  34.   int i, rc;
  35.   WWscreenp = WWCOLMEM;    /* unecessary - color screen memory is default */
  36.   for (i=0;i<27;i++)               /* clear screen */
  37.     printf("                                          "
  38.        "                                          ");
  39.   if ((rc = WWinDef(&Caption)) !=0)       /* set up caption screen */
  40.     {printf("out of memory"); exit(1);}
  41.  
  42.   WWinLoad(&Caption,1,2,NC,NC,"Press arrow keys, ENTER, or hilited char",0);
  43.   WWinLoad(&Caption,2,2,NC,NC,"Pick an item from a drop down menu"
  44.                    " - scroll Dial menu",0);
  45.   WWinLoad(&Caption,3,2,NC,NC,"Press ESC to exit this program",0);
  46.   WWinPut(&Caption);
  47.   WWinCurSet(&Caption,1,1);             /* set cursor out of the way */
  48.  
  49.   LoadUpMenus();                 /* load menu items into windows */
  50.   do
  51.     {
  52.     rc = DoMenus();               /* process menues */
  53.     }
  54.   while (rc != 27);
  55.   Caption.Cursor = NRM_CSR;       /* set cursor back to normal */
  56.   WWinCurSet(&Caption,Caption.UseLength,1);  /* restore cursor */
  57.   }
  58.  
  59.  
  60.  
  61. void LoadUpMenus()
  62. /* this function loads the various windows with menu items and
  63.  * sets hilited chracters. Each menu item in the vertical menus is
  64.  * followed by a 2-digit offset of the hilited character. The
  65.  * hilited chars in the horizontal menus are indicated by a following
  66.  * string that contains dashes where the hilited character is to appear.
  67. */
  68.   {
  69.   unsigned char TopMenu[2][56] =
  70.     {"File   Baudrate   Parity   Transfer   Error   Dial",
  71.      "-      -          -        -          -       -   "};
  72.   unsigned char *FileMenu[] =
  73.               { " New            02",  /* hilite 2nd pos */
  74.                 " Open           02",  /*        "        */
  75.                 " Open Last File 12",  /* hilite 12th pos */
  76.                 " Merge          02",
  77.                 " Save           02",
  78.                 " Save As        07",
  79.                 "                00",  /* space for divider */
  80.                 " Dos Shell      02",
  81.                 " Exit           03"};
  82.   unsigned char Double_Divider[15] =                 /* dbl divider chars */
  83.      {205,205,205,205,205,205,205,205,205,205,205,205,205,205,205};
  84.   unsigned char *BaudMenu[] =
  85.               { "  300 03",
  86.                 " 1200 02",
  87.                 " 2400 02",
  88.                 " 4800 02",
  89.                 " 9600 02",
  90.                 " 19.2 04"};
  91.   unsigned char *ParityMenu[] =
  92.               { " Even 02",
  93.                 " Odd  02",
  94.                 " None 02"};
  95.   unsigned char *TransferMenu[] =
  96.               { " Blind      02",
  97.                 " Kermit     02",
  98.                 " Protocol A 11",
  99.                 " Protocol B 11",
  100.                 " Protocol Z 11"};
  101.   unsigned char *ErrorMenu[] =
  102.               { " Retry 02",
  103.                 " Abort 02"};
  104.   unsigned char *DialMenu[] =
  105.     {" Work             123-456-7890",         /* no hilite */
  106.      " BBS #1           234-567-8901", " BBS #2           345-678-9012",
  107.      " BBS #3           234-567-8901", " BBS #4           345-678-9012",
  108.      " BBS #5           234-567-8901", " BBS #6           345-678-9012",
  109.      " BBS #7           234-567-8901", " BBS #8           345-678-9012",
  110.      " BBS #9           234-567-8901", " BBS #10          345-678-9012",
  111.      " BBS #11          234-567-8901", " BBS #12          345-678-9012",
  112.      " BBS #13          234-567-8901", " BBS #14          345-678-9012",
  113.      " BBS #15          234-567-8901", " BBS #16          345-678-9012",
  114.      " BBS #17          234-567-8901", " BBS #18          345-678-9012",
  115.      " BBS #19          234-567-8901", " BBS #20          345-678-9012",
  116.      " BBS #21          234-567-8901", " BBS #22          345-678-9012",
  117.      " BBS #23          234-567-8901", " BBS #24          345-678-9012",
  118.      " BBS #25          234-567-8901", " BBS #26          345-678-9012"};
  119.   char inkey, *menuptr[6];
  120.   int i, j, k, rc;
  121.  
  122.   menuptr[0] = &FileMenu[0][0];       /* build array of array pointers */
  123.   menuptr[1] = &BaudMenu[0][0];
  124.   menuptr[2] = &ParityMenu[0][0];
  125.   menuptr[3] = &TransferMenu[0][0];
  126.   menuptr[4] = &ErrorMenu[0][0];
  127.  
  128.                         /* load topline */
  129.   if ((rc = WWinDef(&TopLine)) !=0)
  130.     {printf("out of memory"); exit(1);}
  131.   WWinLoad(&TopLine,1,2,NC,NC,TopMenu[0],0);    /* load text */
  132.   for (i=0; i < 56;i++)                         /* load hilited chars */
  133.     if (TopMenu[1][i] == '-')
  134.       WWinLoad(&TopLine,1,2+i,NC,NCB,NULL,1);
  135.   WWinPut(&TopLine);
  136.  
  137.   /* load all vertical menus except phone directory */
  138.   for (i=0;i<5;i++)                            /* for each window */
  139.     {
  140.     if ((rc = WWinDef(&DropWin[i])) !=0)        /* define window */
  141.       {printf("out of memory"); exit(1);}
  142.     for (j=0;j<DropWin[i].UseLength;j++)        /* for each window row */
  143.       {                                         /* load the text */
  144.       WWinLoad(&DropWin[i],j+1,1,NC,NC,
  145.         menuptr[i]+j*(DropWin[i].UseWidth+4),DropWin[i].UseWidth);
  146.                         /* calc the hilite offset */
  147.       k = atoi(menuptr[i]+j*(DropWin[i].UseWidth+4)+DropWin[i].UseWidth+1);
  148.  
  149.       if (k != 0)                               /* hilite the char */
  150.     WWinLoad(&DropWin[i],j+1,k,NC,NCB,NULL,1);
  151.       }/*for j*/
  152.     }/*for i*/
  153.        /* load double-line divider in 1st drop window */
  154.     WWinLoad(&DropWin[0],7,0,NC,NC,"\xc6",1);                     /* |= */
  155.     WWinLoad(&DropWin[0],7,1,NC,NC,Double_Divider,15);             /* =  */
  156.     WWinLoad(&DropWin[0],7,DropWin[0].UseWidth+1,NC,NC,"\xb5",1); /* =| */
  157.  
  158.     /* load the phone directory
  159.      * there are more menu items (27) than will fit on a screen.
  160.      * must load all items, then scroll up and down
  161.     */
  162.     WWScreenLength = 30;              /* trick WW into assigning enough */
  163.     DropWin[5].UseLength = 27;        /* window-memory for table        */
  164.     if ((rc = WWinDef(&DropWin[5])) !=0)        /* define window */
  165.       {printf("out of memory"); exit(1);}
  166.     for (j=0;j<27;j++)                        /* load the text */
  167.       WWinLoad(&DropWin[5],j+1,1,NC,NC, DialMenu[j],30);
  168.     WWScreenLength = 25;              /* correct the screen length */
  169.     DropWin[5].UseLength = 4;         /* correct the window length */
  170.     WWinBorder(&DropWin[5]);          /* correct the border */
  171.     WWinLoad(&DropWin[5],DropWin[5].UseLength+1,  /* write to border */
  172.                12,NC,NC,"scroll",0);
  173.      /* store original memorypointer for test limit and later free */
  174.     hold_Dial_mem_ptr = DropWin[5].MemoryPointer;
  175.   }/* end function LoadUpMenus */
  176.  
  177.  
  178.  
  179.  
  180. int DoMenus()
  181. /* this function handles the presentation of the horizontal and
  182.  * drop-down menus and keeps track of what items were chosen.
  183. */
  184.   {
  185.   struct WWinRC retcde;
  186.   int i, activetop, activedrop, horizitem, done;
  187.   char horizchar, picked[40];
  188.  
  189.   done = 0;
  190.   activetop = 1;                    /* start with first item */
  191.   while (!done)                     /* loop till done != 0 */
  192.     {
  193.     do                                /* horizontal menu processing */
  194.       {
  195.       retcde = WWinHmenu(&TopLine,1,BLACK,NC,BRIGHT|LOOP,activetop);
  196.       activetop = retcde.exval;
  197.       if (retcde.scan == 80)          /* if down-arrow, force ENTER */
  198.     WWinStack("0,13,0");          /* by stac